package com.test.daily.leetcode.y2022.m05.day0515.v01;

/**
 * Solution
 *
 * @author Tom on 2022/5/15
 */
public class Solution {
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,1,2,3,4,6,7};
        int[] ans = twoEven(arr);
        System.out.println(ans[0] + " " + ans[1]);
    }
    // 一个数组中有2个数出现了奇数次,其他数出现了偶数次
    // 求出这两个出现奇数次的数
    public static int[] twoEven(int[] arr){
        int[] ret = new int[2];
        int ex = 0;
        for (int i = 0; i < arr.length; i++) {
            ex=ex^arr[i];
        }
        int rightestOne = ex & (-ex);
        int one = 1;
        for (int i = 0; i < arr.length; i++) {
            if((rightestOne & arr[i]) != 0){
                one ^= arr[i];
            }
        }
        ret[0] = one;
        ret[1] = one ^ ex;
        return ret;
    }
}
